package com.fuqi.android.zhongcai.base.view.activity.deprecated;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;

import com.fuqi.android.zhongcai.R;
import com.bumptech.glide.Glide;
import com.flyco.dialog.listener.OnOperItemClickL;
import com.flyco.dialog.widget.ActionSheetDialog;
import com.fuqi.android.zhongcai.base.Constants;
import com.fuqi.android.zhongcai.base.view.activity.BaseActivity;
import com.fuqi.android.zhongcai.base.view.activity.PhotoPickerActivity;
import com.fuqi.android.zhongcai.base.view.widget.CircleImageView;
import com.fuqi.android.zhongcai.utils.ActivityUtils;

import java.io.File;
import java.util.ArrayList;

import butterknife.Bind;
import butterknife.OnClick;
@Deprecated
public class UserProfileActivity extends BaseActivity {


    @Bind(R.id.iv_header)
    CircleImageView headerImageView;


    @OnClick({R.id.iv_header})
    public void onClickListener(View view) {

        switch (view.getId()) {

            case R.id.iv_header:
                showActionSheet();
                break;

        }

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initViews();

    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == Constants.USER_PICK_PHOTO) {
            if (resultCode == RESULT_OK) {
                ArrayList<String> result = data.getStringArrayListExtra(PhotoPickerActivity.KEY_RESULT);
                Glide.with(this).load(new File(result.get(0))).into(headerImageView);

            }
        }

    }

    private void initViews() {

        titleBar.setTitle("个人中心");

    }


    private void showActionSheet() {
        final String[] stringItems = {"拍照", "从相册选择"};
        final ActionSheetDialog dialog = new ActionSheetDialog(UserProfileActivity.this, stringItems, null);
        dialog.title("选择头像")//
                .titleTextSize_SP(14f)//
                .show();

        dialog.setOnOperItemClickL(new OnOperItemClickL() {
            @Override
            public void onOperItemClick(AdapterView<?> parent, View view, int position, long id) {
                ActivityUtils.toast(stringItems[position]);
                dialog.dismiss();
                if (position == 0) {

                    takePhoto();

                } else {

                    choosePhoto();
                }


            }
        });
    }

    private void takePhoto(){

        ActivityUtils.toast("take photo");

    }


    private void choosePhoto(){

        ActivityUtils.toast("choose photo");
        Intent intent = new Intent(UserProfileActivity.this, PhotoPickerActivity.class);
        intent.putExtra(PhotoPickerActivity.EXTRA_SHOW_CAMERA, false);
        intent.putExtra(PhotoPickerActivity.EXTRA_SELECT_MODE, PhotoPickerActivity.MODE_SINGLE);
        startActivityForResult(intent, Constants.USER_PICK_PHOTO);

    }


    @Override
    public void initView() {

    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {

    }

    @Override
    public boolean hasTitleBar() {
        return true;
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_user_profile;
    }
}
